package com.ht.ruleService;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;

import org.drools.core.impl.StatefulKnowledgeSessionImpl;
import org.drools.core.io.impl.UrlResource;
import org.kie.api.KieBase;
import org.kie.api.KieServices;
import org.kie.api.builder.KieModule;
import org.kie.api.builder.KieRepository;
import org.kie.api.cdi.KBase;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import com.ht.rules.BaoXianInfo;



@Service("RuleService")
@Repository
public class RuleServiceImpl implements RuleService{
	@KBase(name="rules")
	private KieBase kbase;
	
	@Override
	public BigDecimal getBaofei(BaoXianInfo infos) {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/ht/rules/drools-spring.xml");
		StatefulKnowledgeSessionImpl impl= (StatefulKnowledgeSessionImpl) context.getBean("ksession1");
		kbase = impl.getKieBase();
		KieSession ksession = kbase.newKieSession();
		

		ksession.insert(infos);
		ksession.fireAllRules();
	    

		return infos.getBaofei();
	}
	

	public void getTest() {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/ht/rules/drools-spring.xml");
		StatefulKnowledgeSessionImpl impl= (StatefulKnowledgeSessionImpl) context.getBean("ksession1");
		kbase = impl.getKieBase();
		KieSession ksession = kbase.newKieSession();
		BaoXianInfo infos = new BaoXianInfo();
		infos.setCompanyName("BOCG");
		infos.setInsuredSex("N");
		infos.setPlanyear(2);
		infos.setState(1);
		ksession.insert(infos);
		ksession.fireAllRules();
	    

		
	}

}
